package view;

import pojo.Course;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.EventQueue;
public class CourseManager extends JInternalFrame {
    private JScrollPane scrollPane;
    private JTable courseTable;
    private JPanel panel;
    private JLabel label;
    private JTextField textCno;
    private JLabel label_1;
    private JTextField textname;
    private JButton findC;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {

        CourseManager frame = new CourseManager();
        frame.setVisible(true);

    }

    /**
     * Create the frame.
     */
    public CourseManager() {
        setTitle("courseManager");
        setBounds(100, 100, 797, 533);

        scrollPane = new JScrollPane();

        panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "\u8BFE\u7A0B\u641C\u7D22", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GroupLayout groupLayout = new GroupLayout(getContentPane());
        groupLayout.setHorizontalGroup(
                groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                        .addGroup(groupLayout.createSequentialGroup()
                                                .addGap(41)
                                                .addComponent(panel, GroupLayout.PREFERRED_SIZE, 700, GroupLayout.PREFERRED_SIZE))
                                        .addGroup(groupLayout.createSequentialGroup()
                                                .addGap(85)
                                                .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 594, GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(40, Short.MAX_VALUE))
        );
        groupLayout.setVerticalGroup(
                groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                                .addGap(19)
                                .addComponent(panel, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 188, GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(194, Short.MAX_VALUE))
        );

        label = new JLabel("\u8BFE\u7A0B\u7F16\u53F7\uFF1A");

        textCno = new JTextField();
        textCno.setColumns(10);

        label_1 = new JLabel("\u8BFE\u7A0B\u540D\u79F0\uFF1A");

        textname = new JTextField();
        textname.setColumns(10);

        findC = new JButton("\u67E5\u8BE2");
        GroupLayout gl_panel = new GroupLayout(panel);
        gl_panel.setHorizontalGroup(
                gl_panel.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(gl_panel.createSequentialGroup()
                                .addGap(24)
                                .addComponent(label)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(textCno, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
                                .addGap(41)
                                .addComponent(label_1)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textname, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
                                .addGap(110)
                                .addComponent(findC)
                                .addContainerGap(153, Short.MAX_VALUE))
        );
        gl_panel.setVerticalGroup(
                gl_panel.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(gl_panel.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(gl_panel.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label)
                                        .addComponent(textCno, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(label_1)
                                        .addComponent(textname, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(findC))
                                .addContainerGap(41, Short.MAX_VALUE))
        );
        panel.setLayout(gl_panel);

        courseTable = new JTable();
        scrollPane.setViewportView(courseTable);
        courseTable.setModel(new DefaultTableModel(
                new Object[][] {
                },
                new String[] {
                        "\u8BFE\u7A0B\u7F16\u53F7", "\u8BFE\u7A0B\u540D\u79F0", "\u5B66\u5206", "\u5F00\u8BBE\u5E74\u7EA7"
                }
        ) {
            boolean[] columnEditables = new boolean[] {
                    false, true, true, false
            };
            @Override
            public boolean isCellEditable(int row, int column) {
                return columnEditables[column];
            }
        });
        courseTable.getColumnModel().getColumn(0).setPreferredWidth(130);
        courseTable.getColumnModel().getColumn(1).setPreferredWidth(120);
        courseTable.getColumnModel().getColumn(2).setPreferredWidth(113);
        courseTable.getColumnModel().getColumn(3).setPreferredWidth(120);
        getContentPane().setLayout(groupLayout);

        this.fillTable(new Course());

    }
    /**
     * 初始化表格数据
     * @param course
     */
    private void fillTable(Course course){

    }
}
